/**
 * 2009-10-23 下午04:59:03 
 * esignature
 * com.smc.security
 * AuthenticationToken
 */
package com.smc.security;

/**
 * @author chenheng
 * @version 0.0.1
 * 认证授权令牌
 */
public class AuthenticationToken extends AbstractAuthenticationToken {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5615319676203609585L;
	/**
	 * 密码信息
	 */
	private Object credentials ;
	/**
	 * 用户名信息
	 */
	private Object principal ;
	/**
	 * 主键
	 */
	private Object uuid;
	/**
	 * 认证失败后的令牌
	 * @param credentials	
	 * @param principal
	 * @param uuid
	 */
	public AuthenticationToken(Object credentials,Object principal,Object uuid) {
		super(null);
		this.credentials = credentials;
		this.principal = principal ;
		this.uuid = uuid ;
		setAuthenticated(false);
	}
	/**
	 * 认证成功后的令牌
	 * @param credentials
	 * @param principal
	 * @param uuid
	 * @param authorities
	 */
	public AuthenticationToken(Object credentials,Object principal,Object uuid ,GrantedAuthority[] authorities) {
		super(authorities);
		this.credentials = credentials;
		this.principal = principal;
		this.uuid = uuid ;
		super.setAuthenticated(true);
	}
	public Object getCredentials() {
		return credentials;
	}
	public Object getPrincipal() {
		return principal ;
	}
	public Object getUUUID() {
		return uuid;
	}
	/**
	 * 禁止修改用户的认证信息
	 */
	@Override
	public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
		if ( isAuthenticated ) {
			throw new IllegalArgumentException("Cannot set this token to trusted - use constructor " +
					"containing GrantedAutority[]s instead ");
		}
		super.setAuthenticated(false);
	}
}
